package com.spring.sunflower.userinfo

import android.graphics.Color
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.spring.sunflower.R
import com.spring.sunflower.base.BaseActivity
import com.spring.sunflower.bean.CheckApplyFaceVerifyBean
import com.spring.sunflower.bean.FaceAuthStatusBean
import com.spring.sunflower.common.CommonContract
import com.spring.sunflower.constant.Constant

/**
 * Created by Kevin on 2021/8/15<br/>
 *
 * Describe:<br/>
 */
class AuthBeautyActivity : BaseActivity<AuthCenterPresenter>(), CommonContract.AuthCenterView {
    private var clAuthReal: ConstraintLayout? = null
    private var clUserInfo: ConstraintLayout? = null
    private var clBindPhoneNum: ConstraintLayout? = null
    private var tvAuthRealStatus: TextView? = null
    private var tvUserInfoStatus: TextView? = null
    private var tvBindPhoneNumStatus: TextView? = null
    private var llApplyAuthBeauty: LinearLayout? = null
    private var isRealAuthClickable = false
    private var isUserInfoClickable = false
    private var isBindPhoneNumClickable = false
    override fun initView() {
        tvTitle.text = "颜值认证"
        val gender = getField(Constant.KEY_GENDER, Constant.GENDER_MALE)
        clAuthReal = findViewById(R.id.clRealAuth)
        clUserInfo = findViewById(R.id.clUserInfo)
        clBindPhoneNum = findViewById(R.id.clBindPhoneNum)
        tvAuthRealStatus = findViewById(R.id.tvAuthStatus)
        tvUserInfoStatus = findViewById(R.id.tvUserInfoStatus)
        tvBindPhoneNumStatus = findViewById(R.id.tvBindPhoneNumStatus)
        llApplyAuthBeauty = findViewById(R.id.llApplyAuthBeauty)
        clAuthReal?.setOnClickListener { if (isRealAuthClickable) startNewActivity(AuthRealActivity::class.java) }
        clUserInfo?.setOnClickListener {
            if (isUserInfoClickable) startNewActivity(
                UserInfoEditActivity::class.java
            )
        }
        clBindPhoneNum?.setOnClickListener { }
        llApplyAuthBeauty?.setOnClickListener {
            if (isRealAuthClickable) {
                showToast("请先进行真人认证")
                return@setOnClickListener
            }
            if (isUserInfoClickable) {
                showToast("请先完善用户资料")
                return@setOnClickListener
            }
            if (isBindPhoneNumClickable) {
                showToast("请先绑定手机号")
                return@setOnClickListener
            }
            if (gender.equals(Constant.GENDER_MALE)) {
                showToast("男用户无需颜值认证")
                return@setOnClickListener
            }
            mPresenter.requestBeautyAuth()
        }
    }

    override fun onResume() {
        super.onResume()
        mPresenter.getCheckFaceAuthStatus()
        mPresenter.getFaceAuthStatus()
    }

    override fun getLayoutID(): Int = R.layout.activity_auth_beauty

    override fun setPresenter(): AuthCenterPresenter = AuthCenterPresenter(this)

    override fun showFaceAuthStatus(data: FaceAuthStatusBean.DatasBean?) {

    }

    override fun showCheckFaceAuthStatus(data: CheckApplyFaceVerifyBean.DatasBean?) {
        if (data?.authenticate!!) {
            isRealAuthClickable = false
            tvAuthRealStatus?.let {
                it.text = "已认证"
                it.setTextColor(Color.parseColor("#54B83C"))
            }
        } else {
            isRealAuthClickable = true
            tvAuthRealStatus?.let {
                it.text = "未认证"
                it.setTextColor(getColorX(R.color.red_1))
            }

        }
        if (data?.personalInfo!!) {
            isUserInfoClickable = false
            tvUserInfoStatus?.let {
                it.text = "已完善"
                it.setTextColor(Color.parseColor("#54B83C"))
            }
        } else {
            isUserInfoClickable = true
            tvUserInfoStatus?.let {
                it.text = "未完善"
                it.setTextColor(getColorX(R.color.red_1))
            }

        }
        if (data?.mobile!!) {
            isBindPhoneNumClickable = false
            tvBindPhoneNumStatus?.let {
                it.text = "已绑定"
                it.setTextColor(Color.parseColor("#54B83C"))
            }
        } else {
            isBindPhoneNumClickable = true
            tvBindPhoneNumStatus?.let {
                it.text = "未绑定"
                it.setTextColor(getColorX(R.color.red_1))
            }

        }
    }

    override fun beautyAuthApplySuccess() {
        showToast("申请已提交，请耐心等待审核😊")
        finish()
    }
}